#include"comm.hpp"

//测试目的：服务端利用接口发送消息，客户端接收消息
int main()
{
    //1. 创建管道文件
    if(mkfifo(ipcpath.c_str(),MODE)<0)
    {
        perror("mkfifo");
        exit(1);
    }

    //2.文件操作
    int fd = open(ipcpath.c_str(),O_RDONLY);
    if(fd<0)
    {
        perror("open");
        exit(2);
    }

    //3.通信代码
    char buffer[SIZE];
    while(true)
    { 
        memset(buffer,'\0',sizeof(buffer));//初始化
        ssize_t s = read(fd,buffer,sizeof(buffer)-1);
        if(s>0)
        {
            cout<<"client say"<<buffer<<endl;
        }
        else if(s==0)
        {
            //输出到文件结尾
            cerr<<"read end of file, clien quit ,server quit too!"<<endl;
            break;
        }
        else
        { 
            //read error
            perror("read");
            break;
        }
    }
    return 0;
}